
        // //时间的格式化输出
        // let date = new Date();
        // let year = date.getFullYear();
        // let month = date.getMonth()+1;
        // let day = date.getDay();
        // let newdate = year+'/' +month+'/'+day;
        // console.log(newdate)

        //数组的乱序输出
        function shuffleByIndex(array) {
        // 生成索引数组 [0, 1, 2, ..., n-1]，映射函数返回i
        const indices = Array.from({ length: array.length }, (_, i) => i);
        
        // 洗牌算法，从后往前便利，生成随机索引交换
        for (let i = indices.length - 1; i > 0; i--) {
            const j = Math.floor(Math.random() * (i + 1));
            [indices[i], indices[j]] = [indices[j], indices[i]];
        }
        
        // 根据打乱的索引重组数组
        return indices.map(index => array[index]);
        }
        // 使用示例
        const original = [2,45,1,8,2];
        const shuffled = shuffleByIndex(original);
        console.log(shuffled); // 例如: [4, 1, 5, 3, 2]


        //循环嵌套法
        const source = [
            { id: 1, pid: 0, name: 'body' },
            { id: 2, pid: 1, name: 'title' },
            { id: 3, pid: 2, name: 'div' }
        ];
        function convertToTree(items) {
            const tree = [];
            // 遍历每个节点
            items.forEach(item => {
                // 如果没有父节点，直接作为根节点
                if (item.pid === 0) {
                    tree.push(item);
                    return;
                }
                // 查找父节点
                const parent = items.find(i => i.id === item.pid);
                if (parent) {
                    // 如果父节点没有 children 数组，创建一个
                    parent.children = parent.children || [];
                    parent.children.push(item);
                    }
                });
            
            return tree;
        }
        let asd = convertToTree(source);
        console.log(asd)

   